/**
 * api接口统一管理
 */
import http from "./http";
// const baseHost = process.env.NODE_ENV === "development" ? "https://testminiapi.wxcwy.com" : "https://miniapi.wxcwy.com";
const baseHost = "https://miniapi.wxcwy.com"
// const baseHost = "http://admin.cwy.com:8080"
import store from '../store/index'
const API = {
  /**
   * @module 登录注册
   */

  // 小程序code登录
  onWxLogin(params) {
    return http.postToken(baseHost + "/api/auth/login-wx", params);
  },

  // 账号密码登录
  onWxLoginPassword(params) {
    return http.post(baseHost + "/api/auth/login-password", params);
  },

  // 手机短信登录
  onWxLoginVcode(params) {
    return http.post(baseHost + "/api/auth/login-vcode", params);
  },

  // 已登录用户基础信息
  loggedinUserInfo(params) {
    return http.post(baseHost + "/api/profile", params);
  },

  // 刷新Token
  refreshToken(params) {
    return http.post(baseHost + "/api/auth/refresh", params);
  },

  // 登出
  onLogout(params) {
    return http.post(baseHost + "/api/auth/logout", params);
  },

  //用户授权获取用户信息
  getWxUserInfo(params) {
    return http.post(baseHost + "/api/auth/decrypt-wxuser", params);
  },

  //用户授权获取用户手机号
  getWxPhoneNumber(params) {
    return http.post(baseHost + "/api/auth/decrypt-wxmobile", params);
  },

  /**
 * @module 首页
 */
  //首页
  getIndex(params) {
    return http.get(baseHost + "/api/index", params);
  },

  //刷新美粉币
  getBalance(params) {
    return http.post(baseHost + "/api/balance", params);
  },

  //商品详情
  productDetail(params) {
    return http.get(baseHost + `/api/product/${params.product_id}`, params);
  },

  //爆品列表|商品列表
  productList(params) {
    return http.get(baseHost + `/api/product`, params);
  },

  //活动详情
  operatingDetail(params) {
    return http.get(baseHost + `/api/operating/${params.id}`, params);
  },


  /**
 * @module 附近
 */

  //附近商户列表
  getMerchantNear(params) {
    return http.get(baseHost + "/api/merchant-near", params);
  },
  // 逆地理位置解析
  getMerchantMapTitle(params) {
    return http.get(baseHost + "/api/merchant-map-title", params);
  },

  /**
 * @module 商户联盟
 */
  //商户联盟列表
  getMerchant(params) {
    return http.get(baseHost + "/api/merchant", params);
  },

  //商户联盟分类
  getMerchantCategory(params) {
    return http.get(baseHost + "/api/merchant-category", params);
  },

  //商户联盟详情
  getMerchantDetail(params) {
    return http.get(baseHost + `/api/merchant/${params.id}`, params);
  },

  /**
* @module 我的
*/
  //修改昵称
  changeNickName(params) {
    let { id, union_id } = store.state.userInfo
    params = Object.assign(params, { user_id: id, union_id })
    return http.post(baseHost + "/api/change-nick-name", params);
  },

  //修改手机号
  changeMobile(params) {
    let { id, union_id } = store.state.userInfo
    params = Object.assign(params, { user_id: id, union_id })
    return http.post(baseHost + "/api/change-mobile", params);
  },

  //微信手机号,姓名快速认证
  changeUsername(params) {
    let { id, union_id } = store.state.userInfo
    params = Object.assign(params, { user_id: id, union_id })
    return http.post(baseHost + "/api/auth-username-wxmobile", params);
  },

  /**
* @module 分销中心
*/



  //头部汇总
  getStoreIndex(params) {
    return http.get(baseHost + `/api/store/index`, params);
  },

  //今日美粉币动态
  getStoreDynamic(params) {
    return http.get(baseHost + `/api/store/dynamic`, params);
  },

  //美粉币动态
  getStoreDynamicAll(params) {
    return http.get(baseHost + `/api/store/dynamic-all`, params);
  },

  //我的会员|今日会员
  getStoreMember(params) {
    return http.get(baseHost + `/api/store/member`, params);
  },

  //申请提现
  postWithdrawal(params) {
    return http.post(baseHost + `/api/withdrawal`, params);
  },

  //提现列表
  getWithdrawal(params) {
    return http.get(baseHost + `/api/withdrawal`, params);
  },

  //提现信息
  getWithdrawalInfo(params) {
    return http.get(baseHost + `/api/withdrawal/info`, params);
  },

  /**
* @module 充值
*/

  //美粉币充值
  recharge(params) {
    let { open_id } = store.state.loginInfo
    params = Object.assign(params, { open_id })
    return http.post(baseHost + "/api/recharge", params);
  },

  //关闭充值
  rechargeCancel(params) {
    return http.put(baseHost + `/api/recharge/${params.id}/cancel`, params);
  },

  //充值列表
  rechargeList(params) {
    return http.get(baseHost + "/api/recharge", params);
  },

  //充值详情
  rechargeDetail(params) {
    return http.get(baseHost + `/api/recharge/${params.id}`, params);
  },

  /**
* @module 订单
*/

  //订单列表
  getOrderList(params) {
    return http.get(baseHost + `/api/order`, params);
  },

  //订单详情
  getOrderDetail(params) {
    return http.get(baseHost + `/api/order/${params.id}`, params);
  },

  //商品下单
  postOrder(params) {
    return http.post(baseHost + `/api/order`, params);
  },

  //订单余额支付
  postOrderPayment(params) {
    return http.post(baseHost + `/api/order/payment`, params);
  },

  //订单微信支付
  postOrderPaymentWechat(params) {
    let { open_id } = store.state.loginInfo
    params = Object.assign(params, { open_id })
    return http.post(baseHost + `/api/order/payment-wechat`, params);
  },

  //取消订单
  postOrderCancel(params) {
    return http.post(baseHost + `/api/order/cancel`, params);
  },

  //确认收货
  postOrderConfirm(params) {
    return http.post(baseHost + `/api/order/confirm`, params);
  },


  /**
* @module 公用
*/

  //开通城市字典接口
  getCommonCity(params) {
    return http.get(baseHost + "/api/common/city", params);
  },

  //随机推荐[商铺|商铺推荐]
  getRandomRecommend(params) {
    return http.get(baseHost + "/api/random-recommend", params);
  },

  //发送短信
  sendSms(params) {
    return http.post(baseHost + "/api/sms/send", params);
  },

  //美粉币返币协议
  getCommonProtocol(params) {
    return http.get(baseHost + "/api/common/protocol", params);
  },
  //获取微信商户ID
  getWxMerchId() {
    return http.get(baseHost + "/api/common/wx-merchant-id");
  },

  /**
* @module 我的二维码|订单核销码|卡券核销码
*/
  getQrCode(params) {
    return http.post(baseHost + "/api/qr-code", params);
  },

  /**
* @module 分享
*/
  //获取分享码
  getShareCode(params) {
    return http.get(baseHost + "/api/share/code", params);
  },

  //获取shareId
  getShareId(params) {
    return http.post(baseHost + "/api/share", params);
  },

  //分享记录点击
  postShareClick(params) {
    return http.post(baseHost + "/api/share/click", params);
  },

  //邀请注册页面数据
  getShare(params) {
    return http.get(baseHost + "/api/share", params);
  },

  //商品小程序码
  getShareProductCode(params) {
    return http.post(baseHost + "/api/share/product/qrcode", params);
  },

  //邀请小程序码
  getShareInviteCode(params) {
    return http.post(baseHost + "/api/share/invite/qrcode", params);
  },

  //邀请人信息
  getShareInfo(params) {
    return http.get(baseHost + "/api/share/info", params);
  },


  /**
* @module 我的
*/

  //头部汇总
  getUserSales(params) {
    return http.get(baseHost + "/api/user-sales", params);
  },

  //中间banner
  getUserBanner(params) {
    return http.get(baseHost + "/api/user/banner", params);
  },

  /**
* @module 卡券
*/
  //卡券列表
  getCardList(params) {
    return http.get(baseHost + "/api/card", params);
  },

  //卡券激活
  postCardActivate(params) {
    return http.post(baseHost + "/api/card/activate", params);
  },

  //卡券信息
  getCardInfo(params) {
    return http.get(baseHost + `/api/card/${params.card_id}`, params);
  },

  //受赠人信息校对
  cardUserCheck(params) {
    return http.post(baseHost + `/api/card/user-check`, params);
  },

  //卡券消费记录
  getcardRecords(params) {
    return http.get(baseHost + `/api/card/records`, params);
  },

  //卡券激活照片上传
  cardUploadImg() {
    return baseHost + `/api/card/upload-img`;
  },

  //卡券激活照片删除
  cardDestroyImg(params) {
    return http.post(baseHost + `/api/card/destroy-img`, params);
  },

  //卡券转赠
  cardGiving(params) {
    return http.post(baseHost + `/api/card/giving`, params);
  },

  /**
  * @module 卡券
  */

  //优惠券列表
  getCoupon(params) {
    return http.get(baseHost + `/api/coupon`, params);
  },

  //可用优惠券列表
  getCouponAvailable(params) {
    return http.get(baseHost + `/api/coupon-available`, params);
  },

  //兑换[优惠券]详情
  getExchangeShow(params) {
    return http.get(baseHost + `/api/coupon/exchange-show`, params);
  },
  
  //兑换[商品]详情
  getExchangeProductShow(params) {
    return http.get(baseHost + `/api/coupon/exchange-product-show`, params);
  }, 
  
  //兑换优惠券
  postCouponExchange(params) {
    return http.post(baseHost + `/api/coupon/exchange`, params);
  },
  
  //兑换商品
  postCouponExchangeProduct(params) {
    return http.post(baseHost + `/api/coupon/exchange-product`, params);
  },

  //获取商品分类
  getProductCategory(params) {
    return http.get(baseHost + `/api/product-category`, params);
  },

};
export default API;
